package com.acwing.partition8;

import java.io.*;

/**
 * @author `RKC`
 * @date 2022/2/26 15:27
 */
public class AC788逆序对的数量 {

    private static final int N = 100010;
    private static int[] nums = new int[N], temp = new int[N];
    private static int n = 0;

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        n = Integer.parseInt(reader.readLine());
        String[] ss = reader.readLine().split(" ");
        for (int i = 0; i < n; i++) nums[i] = Integer.parseInt(ss[i]);
        writer.write(mergeSort(nums, 0, n - 1) + "\n");
        writer.flush();
    }

    private static long mergeSort(int[] nums, int l, int r) {
        if (l >= r) return 0;
        int mid = l + r >> 1;
        long res = mergeSort(nums, l, mid) + mergeSort(nums, mid + 1, r);
        int i = l, j = mid + 1, k = 0;
        while (i <= mid && j <= r) {
            if (nums[i] <= nums[j]) temp[k++] = nums[i++];
            else {
                res += mid - i + 1;
                temp[k++] = nums[j++];
            }
        }
        while (i <= mid) temp[k++] = nums[i++];
        while (j <= r) temp[k++] = nums[j++];
        for (i = l, j = 0; i <= r; i++, j++) nums[i] = temp[j];
        return res;
    }
}
